package com.xfatm.simplebrowser.ui;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ProgressBar;

import com.xfatm.simplebrowser.R;
import com.xfatm.simplebrowser.util.BeanManageUtils;

/**
 * Created by wenjie on 2018/3/12.
 */

public class MainWebChromeClient extends WebChromeClient{
    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        //加载进度条
        ProgressBar progressBar= BeanManageUtils.getBean("loadProgressBar",ProgressBar.class);
        if(progressBar!=null){
            if(newProgress==100){
                progressBar.setVisibility(View.GONE);
            }else{
                progressBar.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
                progressBar.setProgress(newProgress);//设置进度值
            }
        }
        super.onProgressChanged(view, newProgress);
    }

    //显示标题
    @Override
    public void onReceivedTitle(WebView view, String title) {
        super.onReceivedTitle(view, title);
        EditText urlET=BeanManageUtils.getBean(R.id.urlText,EditText.class);
        urlET.setText(title);
    }
}
